import requests

import app

# 登录成功
reps = requests.post(url=app.BASE_URL + "/api/sys/login",
                     headers=app.HEADERS,
                     json={"mobile": "13800000002",
                           "password": "123456"})
# 获取 拼接 登录令牌
token = "Bearer " + reps.json().get("data")
print("登录成功:", reps.json())
# 列表中  存在的key是修改,不存在的key是追加
app.HEADERS["Authorization"] = token
#  新增员工信息
res_data = {"username": "张三三", "mobile": "14534567897", "timeOfEntry": "2021-05-12", "formOfEmployment": 1,
            "workNumber": "9807", "departmentName": "行政部", "departmentId": "1390276668836352000",
            "correctionTime": "2021-05-17T16:00:00.000Z"}

res = requests.post(url=app.BASE_URL + "/api/sys/user", headers=app.HEADERS, json=res_data)
#  获取增加员工的id值
emp_id = res.json().get("data").get("id")
print("添加员工成功", res.json())
print("员工id号:", emp_id)

# 查询员工
resp = requests.get(url=app.BASE_URL + "/api/sys/user/" + emp_id, headers=app.HEADERS)
print("查询员工:", resp.json())

# 修改员工
res_data = {"username": "电麦腿.赵四"}
resp = requests.put(url=app.BASE_URL + "/api/sys/user/" + emp_id, headers=app.HEADERS, json=res_data)
print("修改员工:", resp.json())

#  删除员工
resp = requests.delete(url=app.BASE_URL + "/api/sys/user/" + emp_id, headers=app.HEADERS)
print("删除员工:", resp.json())
#  查询员工列表
resp = requests.get(url=app.BASE_URL + "/api/sys/user?page=1&size=10", headers=app.HEADERS)
print("查询员工列表", resp.json())

'''
import requests
import app
resp = requests.post(url=app.BASE_URL + "/api/sys/login", headers=app.HEADERS,
                     json={"mobile": "13800000002", "password": "123456"})
token = "Bearer " + resp.json().get("data")
app.HEADERS["Authorizationn"] = token
res_data = {"username": "张三三", "mobile": "14534567897", "timeOfEntry": "2021-05-12", "formOfEmployment": 1,
            "workNumber": "9807", "departmentName": "行政部", "departmentId": "1390276668836352000",
            "correctionTime": "2021-05-17T16:00:00.000Z"}
res = requests.post(url=app.BASE_URL + "/api/sys/user", headers=app.HEADERS, json=res_data)

emp_id = res.json().get("data").get("id")
resp = requests.get(url=app.BASE_URL + "/api/sys/user/" + emp_id, headers=app.HEADERS)
res_data = {"username": "电麦腿.赵四"}
resp = requests.put(url=app.BASE_URL + "/api/sys/user/" + emp_id, headers=app.HEADERS, json=res_data)
resp = requests.delete(url=app.BASE_URL + "/api/sys/user/" + emp_id, headers=app.HEADERS)
resp = requests.get(url=app.BASE_URL + "/api/sys/user?page=1&size=10", headers=app.HEADERS)
'''
